---
description: How to connect, disconnect, handle errors and check the connection status of the Triplit sync engine.
---

# Sync Engine

## Connecting and disconnecting

Instantiating a client will automatically connect to the server. If the connection is unexpectedly lost, the client will automatically reconnect.

You may also manually manage the state connection to the server by calling `client.connect()` and `client.disconnect()`.

The connection parameters used in the client constructor can be updated by using the Sessions API. Read more about it in the [auth guide](/auth)

## Connection status

The connection status is available at `client.connectionStatus`.

You may also listen to changes in the connection status by adding a listener to `client.onConnectionStatusChange(callback, runImmediately)`. If the optional parameter `runImmediately` is set to `true`, the callback will be run immediately with the current connection status.

```typescript
client.onConnectionStatusChange((status) => {
  if (status === 'OPEN') console.log('Connected to server');
  if (status === 'CLOSED') console.log('Disconnected from server');
}, true);
```

## Handling errors

Read the [event listeners](/client/event-listeners) documentation for more information on how to handle errors over sync.
